package com.kobe.task.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.kobe.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kobe.common.annotation.Log;
import com.kobe.common.core.controller.BaseController;
import com.kobe.common.core.domain.AjaxResult;
import com.kobe.common.enums.BusinessType;
import com.kobe.task.domain.SysOaTask;
import com.kobe.task.service.ISysOaTaskService;
import com.kobe.common.utils.poi.ExcelUtil;
import com.kobe.common.core.page.TableDataInfo;

/**
 * 任务管理Controller
 *
 * @author ruoyi
 * @date 2025-10-18
 */
@RestController
@RequestMapping("/project/task")
public class SysOaTaskController extends BaseController
{
    @Autowired
    private ISysOaTaskService sysOaTaskService;

    /**
     * 查询任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOaTask sysOaTask)
    {
        startPage();
        List<SysOaTask> list = sysOaTaskService.selectSysOaTaskList(sysOaTask);
        return getDataTable(list);
    }
    /**
     * 根据项目id查询任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:task:list')")
    @GetMapping("/listByProjectId")
    public TableDataInfo listByProjectId(SysOaTask sysOaTask){
        startPage();
        List<SysOaTask> list = sysOaTaskService.selectSysOaTaskListByProjectId(sysOaTask.getProjectId());
        System.out.println(list);
        return getDataTable(list);
    }
    /**
     * 导出任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:task:export')")
    @Log(title = "任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOaTask sysOaTask)
    {
        List<SysOaTask> list = sysOaTaskService.selectSysOaTaskList(sysOaTask);
        ExcelUtil<SysOaTask> util = new ExcelUtil<SysOaTask>(SysOaTask.class);
        util.exportExcel(response, list, "任务管理数据");
    }

    /**
     * 获取任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(sysOaTaskService.selectSysOaTaskByTaskId(taskId));
    }

    /**
     * 新增任务管理
     */
    @PreAuthorize("@ss.hasPermi('project:task:add')")
    @Log(title = "任务管理", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 3000,message = "请勿重复添加")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody SysOaTask sysOaTask)
    {
        return toAjax(sysOaTaskService.insertSysOaTask(sysOaTask));
    }

    /**
     * 修改任务管理
     */
    @PreAuthorize("@ss.hasPermi('project:task:edit')")
    @Log(title = "任务管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 3000,message = "请勿重复修改")
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody SysOaTask sysOaTask)
    {
        return toAjax(sysOaTaskService.updateSysOaTask(sysOaTask));
    }

    /**
     * 删除任务管理
     */
    @PreAuthorize("@ss.hasPermi('project:task:remove')")
    @Log(title = "任务管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(sysOaTaskService.deleteSysOaTaskByTaskIds(taskIds));
    }
}

